import { useEffect } from "react";
import { useState } from "react";

export function useWindowScroll() {

  const [y, setY] = useState(0);

  useEffect(() => {
    const listenWindowScroll = function() {
      setY(document.documentElement.scrollTop);
    }
    window.addEventListener('scroll', listenWindowScroll);
    return () => {
      window.removeEventListener('scroll', listenWindowScroll);
    }
  }, [])

  return [y];
}